<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:PropertyTools.Wpf"
                    xmlns:converters="clr-namespace:PropertyTools.Wpf"
                    xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">

    <!-- 
    Portions are copied from ColorPicker styles by Ury Jamshy, 21 July 2011.
    See http://www.codeproject.com/KB/WPF/ColorPicker010.aspx
    The Code Project Open License (CPOL)
    http://www.codeproject.com/info/cpol10.aspx
    -->

    <local:ColorToBrushConverter x:Key="ColorToBrushConverter2" />
    <local:ColorToHexConverter x:Key="ColorToHexConverter2" />
    <converters:ColorToStringConverter x:Key="ColorToStringConverter2" />
    <local:ColorToComponentConverter x:Key="ColorToComponentConverter2" />
    <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
    <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter2" InvertVisibility="True" />
    <local:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter" />
    <local:DefinedColorToVisibilityConverter x:Key="DefinedColorToVisibilityConverter" />

    <BitmapImage x:Key="ColorPickerImageSource" UriSource="ColorPicker.png" />

    <BitmapImage x:Key="HsvImageSource" UriSource="Hsv.png" />

    <DrawingBrush x:Key="CheckersBrush" Viewport="0,0,11,11" ViewportUnits="Absolute" TileMode="Tile">
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <GeometryDrawing Geometry="M0,0 L2,0 2,2, 0,2Z" Brush="White" />
                <GeometryDrawing Geometry="M0,1 L2,1 2,2 1,2 1,0 0,0Z" Brush="LightGray" />
            </DrawingGroup>
        </DrawingBrush.Drawing>
    </DrawingBrush>

    <DrawingBrush x:Key="SmallCheckerBoardBrush2" Viewport="0,0,7,7" ViewportUnits="Absolute" TileMode="Tile">
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <GeometryDrawing Brush="White">
                    <GeometryDrawing.Geometry>
                        <RectangleGeometry Rect="0,0,1,1" />
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>

                <GeometryDrawing Brush="Black">
                    <GeometryDrawing.Geometry>
                        <GeometryGroup>
                            <RectangleGeometry Rect="0,0,0.50,0.50" />
                            <RectangleGeometry Rect="0.50,0.50,0.50,0.50" />
                        </GeometryGroup>
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
            </DrawingGroup>
        </DrawingBrush.Drawing>
    </DrawingBrush>

    <DataTemplate x:Key="ColorPresenterTemplate">
        <StackPanel Margin="4 0 4 0" Orientation="Horizontal" IsHitTestVisible="false">
            <Grid Width="13" Height="13" VerticalAlignment="Center">
                <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                   Fill="{StaticResource SmallCheckerBoardBrush2}" SnapsToDevicePixels="True"
                   Visibility="{Binding Converter={StaticResource DefinedColorToVisibilityConverter}}" />
                <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                   Fill="{Binding Converter={StaticResource ColorToBrushConverter2}}" Stroke="Gray" SnapsToDevicePixels="True" />
                <Polyline Points="2,2 11,11" Stroke="Black" StrokeThickness="2"
                  Visibility="{Binding Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter={x:Static local:ColorHelper.Automatic}}" />
                <Polyline Points="2,11 11,2" Stroke="Black" StrokeThickness="2"
                  Visibility="{Binding Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter={x:Static local:ColorHelper.Automatic}}" />
                <TextBlock Text="?" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" 
                       Visibility="{Binding Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter={x:Static local:ColorHelper.UndefinedColor}}" />
            </Grid>
            <TextBlock Margin="8 0 0 0" VerticalAlignment="Center"
                 Text="{Binding Converter={StaticResource ColorToStringConverter2}}" />
        </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="ColorItemTemplate">
        <Grid Margin="1 2 1 2" Width="13" Height="13" HorizontalAlignment="Center" SnapsToDevicePixels="True"
          ToolTip="{Binding Converter={StaticResource ColorToStringConverter2}}">
            <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                 Fill="{StaticResource SmallCheckerBoardBrush2}" SnapsToDevicePixels="True"
                 Visibility="{Binding Converter={StaticResource DefinedColorToVisibilityConverter}}" />
            <Rectangle Stroke="#e2e4e7"
                 Fill="{Binding Converter={StaticResource ColorToBrushConverter2}, UpdateSourceTrigger=PropertyChanged}"
                 SnapsToDevicePixels="True" />
            <Polyline Points="2,2 11,11" Stroke="Black" StrokeThickness="2"
                Visibility="{Binding Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter={x:Static local:ColorHelper.Automatic}}" />
            <Polyline Points="2,11 11,2" Stroke="Black" StrokeThickness="2"
                Visibility="{Binding Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter={x:Static local:ColorHelper.Automatic}}" />
            <TextBlock Text="?" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" 
                       Visibility="{Binding Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter={x:Static local:ColorHelper.UndefinedColor}}" />
        </Grid>
    </DataTemplate>

    <Style x:Key="ColorItemContainerStyle" TargetType="ListBoxItem">
        <Setter Property="Padding" Value="0" />
    </Style>

    <!--<DataTemplate x:Key="ColorItemTemplate2">
        <Grid Background="{StaticResource SmallCheckerBoardBrush2}" Margin="0 2 2 -1" Width="13" Height="13"
          HorizontalAlignment="Center">
            <Rectangle
Fill="{Binding Converter={StaticResource ColorToBrushConverter2}, UpdateSourceTrigger=PropertyChanged}"
SnapsToDevicePixels="True" />
        </Grid>
    </DataTemplate>-->

    <Style x:Key="ComboBoxFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle Margin="4,4,21,4" StrokeThickness="1"
                     Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeDashArray="1 2" SnapsToDevicePixels="true" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <LinearGradientBrush x:Key="ButtonNormalBackground" StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="#F3F3F3" Offset="0" />
            <GradientStop Color="#EBEBEB" Offset="0.5" />
            <GradientStop Color="#DDDDDD" Offset="0.5" />
            <GradientStop Color="#CDCDCD" Offset="1" />
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070" />

    <Geometry x:Key="DownArrowGeometry">
        M 0 0 L 3.5 4 L 7 0 Z
    </Geometry>

    <Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="IsTabStop" Value="false" />
        <Setter Property="Focusable" Value="false" />
        <Setter Property="ClickMode" Value="Press" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <theme:ButtonChrome Name="Chrome" Background="{TemplateBinding Background}"
                              BorderBrush="{TemplateBinding BorderBrush}" RenderMouseOver="{TemplateBinding IsMouseOver}"
                              RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="true">
                        <Grid Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
                  HorizontalAlignment="Right">
                            <Path Name="Arrow" Margin="3,1,0,0" Fill="Black" Data="{StaticResource DownArrowGeometry}"
                    HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Grid>
                    </theme:ButtonChrome>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Setter TargetName="Chrome" Property="RenderPressed" Value="true" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="Arrow" Property="Fill" Value="#AFAFAF" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ItemsPanelTemplate x:Key="ColorItemsPanelTemplate">
        <UniformGrid Margin="0 2 0 2" Columns="10" HorizontalAlignment="Center"/>
    </ItemsPanelTemplate>

    <Style x:Key="HeaderBackground" TargetType="{x:Type Grid}">
        <Setter Property="Background" Value="#f0f2f5" />
    </Style>

    <Style x:Key="HeaderStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="Padding" Value="2" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="Background" Value="#f0f2f5" />
    </Style>

    <Style x:Key="ComponentStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="Padding" Value="2" />
    </Style>

    <Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}">
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="Margin" Value="1" />
        <Setter Property="Background" Value="#e0e0e0" />
        <Setter Property="TextAlignment" Value="Right" />
    </Style>

    <Style x:Key="SliderStyle" TargetType="{x:Type Slider}">
        <Setter Property="Width" Value="60" />
    </Style>

    <Style x:Key="Box" TargetType="{x:Type ListBox}">
        <Setter Property="BorderBrush" Value="#828790" />
        <Setter Property="BorderThickness" Value="0 1 0 1" />
    </Style>

    <Style x:Key="BottomBox" TargetType="{x:Type ListBox}">
        <Setter Property="BorderBrush" Value="#828790" />
        <Setter Property="BorderThickness" Value="0 1 0 0" />
    </Style>

    <Style x:Key="BoxB" TargetType="{x:Type Border}">
        <Setter Property="BorderBrush" Value="#828790" />
        <Setter Property="BorderThickness" Value="0 1 0 1" />
    </Style>

    <Style x:Key="BottomBoxB" TargetType="{x:Type Border}">
        <Setter Property="BorderBrush" Value="#828790" />
        <Setter Property="BorderThickness" Value="0 1 0 0" />
    </Style>

    <Style TargetType="{x:Type local:ColorPickerPanel}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ColorPickerPanel}">
                    <StackPanel>
                        <Grid Style="{StaticResource HeaderBackground}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <TextBlock Style="{StaticResource HeaderStyle}"
                         Text="{Binding Strings.ThemeColors,RelativeSource={RelativeSource Mode=TemplatedParent}}"
                         Visibility="{Binding ShowHsvPanel, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource BoolToVisibilityConverter2}}" />
                            <TextBlock Grid.Column="0" Style="{StaticResource HeaderStyle}"
                         Text="{Binding Strings.HSV,RelativeSource={RelativeSource Mode=TemplatedParent}}"
                         Visibility="{Binding ShowHsvPanel, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource BoolToVisibilityConverter}}" />

                            <ToggleButton Grid.Column="1" Padding="0"
                            ToolTip="{Binding Strings.ColorPickerToolTip,RelativeSource={RelativeSource Mode=TemplatedParent}}"
                            IsChecked="{Binding IsPicking, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                            Style="{StaticResource {x:Static ToolBar.ToggleButtonStyleKey}}">
                                <ToggleButton.Content>
                                    <Image Source="{StaticResource ColorPickerImageSource}" Stretch="None" />
                                </ToggleButton.Content>
                            </ToggleButton>
                            <ToggleButton
                            ToolTip="{Binding Strings.TogglePanelToolTip,RelativeSource={RelativeSource Mode=TemplatedParent}}"
IsChecked="{Binding ShowHsvPanel, RelativeSource={RelativeSource Mode=TemplatedParent}}" Grid.Column="2" Padding="0"
Style="{StaticResource {x:Static ToolBar.ToggleButtonStyleKey}}">
                                <ToggleButton.Content>
                                    <Image Source="{StaticResource HsvImageSource}" Stretch="None" />
                                </ToggleButton.Content>
                            </ToggleButton>
                        </Grid>
                        <Grid
Visibility="{Binding ShowHsvPanel, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource BoolToVisibilityConverter2}}">
                            <StackPanel x:Name="PART_PredefinedColorPanel">
                                <ListBox
ItemsSource="{Binding ThemeColors, RelativeSource={RelativeSource Mode=TemplatedParent}}"
BorderThickness="0 1 0 1" ItemTemplate="{StaticResource ColorItemTemplate}" ItemContainerStyle="{StaticResource ColorItemContainerStyle}"
ItemsPanel="{StaticResource ColorItemsPanelTemplate}" />
                                <TextBlock
Text="{Binding Strings.StandardColors,RelativeSource={RelativeSource Mode=TemplatedParent}}"
Style="{StaticResource HeaderStyle}" />
                                <ListBox Style="{StaticResource Box}"
                         ItemsSource="{Binding StandardColors, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                         ItemTemplate="{StaticResource ColorItemTemplate}"  ItemContainerStyle="{StaticResource ColorItemContainerStyle}" ItemsPanel="{StaticResource ColorItemsPanelTemplate}" />
                                <TextBlock
Text="{Binding Strings.OpacityVariations,RelativeSource={RelativeSource Mode=TemplatedParent}}"
Style="{StaticResource HeaderStyle}" />
                                <ListBox Style="{StaticResource Box}"
                         ItemsSource="{Binding OpacityVariations, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                         ItemTemplate="{StaticResource ColorItemTemplate}" ItemContainerStyle="{StaticResource ColorItemContainerStyle}" ItemsPanel="{StaticResource ColorItemsPanelTemplate}" />
                                <TextBlock
Text="{Binding Strings.RecentColors,RelativeSource={RelativeSource Mode=TemplatedParent}}"
Style="{StaticResource HeaderStyle}" />
                                <ListBox Style="{StaticResource BottomBox}"
                         ItemsSource="{Binding RecentColors, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                         ItemTemplate="{StaticResource ColorItemTemplate}" ItemContainerStyle="{StaticResource ColorItemContainerStyle}" ItemsPanel="{StaticResource ColorItemsPanelTemplate}" />
                            </StackPanel>
                        </Grid>
                        <Grid
Visibility="{Binding ShowHsvPanel, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource BoolToVisibilityConverter}}">
                            <StackPanel>
                                <Border Style="{StaticResource BoxB}">
                                    <Grid Margin="4">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>
                                        <local:HsvControl x:Name="PART_HSV" Margin="1 0 1 0" BorderBrush="Gray" BorderThickness="1"
                                      SelectedColor="{Binding SelectedColor, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                      Hue="{Binding Hue, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                      Saturation="{Binding Saturation, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                      Value="{Binding Brightness, RelativeSource={RelativeSource Mode=TemplatedParent}}" Height="100" />
                                        <local:SpectrumSlider BorderBrush="Gray" BorderThickness="1"
                                          Value="{Binding Hue, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                                              Grid.Row="0" Grid.Column="1" />
                                        <local:ColorSlider Grid.Row="1" Grid.Column="0"
                                                           Background="{StaticResource CheckersBrush}"
                                       Value="{Binding Alpha, RelativeSource={RelativeSource Mode=TemplatedParent}}" BorderBrush="Gray" BorderThickness="1"
                                       LeftColor="#00000000" RightColor="#FF000000" />

                                    </Grid>
                                </Border>
                                <TextBlock
Text="{Binding Strings.Values,RelativeSource={RelativeSource Mode=TemplatedParent}}"
Style="{StaticResource HeaderStyle}" />
                                <Border Style="{StaticResource BottomBoxB}">
                                    <Grid Margin="2">
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="20" />
                                            <ColumnDefinition Width="30" />
                                            <ColumnDefinition Width="10" />
                                            <ColumnDefinition Width="16" />
                                            <ColumnDefinition Width="30" />
                                            <ColumnDefinition Width="40" />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="R:" Style="{StaticResource ComponentStyle}" Grid.Row="0" />
                                        <TextBlock Text="G:" Style="{StaticResource ComponentStyle}" Grid.Row="1" Grid.Column="0" />
                                        <TextBlock Text="B:" Style="{StaticResource ComponentStyle}" Grid.Row="2" Grid.Column="0" />
                                        <TextBlock Text="A:" Style="{StaticResource ComponentStyle}" Grid.Row="3" Grid.Column="0" />

                                        <TextBlock Text="H:" Style="{StaticResource ComponentStyle}" Grid.Row="0" Grid.Column="3" />
                                        <TextBlock Text="S:" Style="{StaticResource ComponentStyle}" Grid.Row="1" Grid.Column="3" />
                                        <TextBlock Text="B:" Style="{StaticResource ComponentStyle}" Grid.Row="2" Grid.Column="3" />

                                        <TextBlock Text="&#176;" Style="{StaticResource ComponentStyle}" Grid.Row="0"
                               Grid.Column="5" />
                                        <TextBlock Text="%" Style="{StaticResource ComponentStyle}" Grid.Row="1"
                               Grid.Column="5" />
                                        <TextBlock Text="%" Style="{StaticResource ComponentStyle}" Grid.Row="2"
                               Grid.Column="5" />

                                        <TextBox Grid.Row="0" Grid.Column="1" Style="{StaticResource TextBoxStyle}"
                             Text="{Binding Red, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                        <TextBox Grid.Row="1" Grid.Column="1" Style="{StaticResource TextBoxStyle}"
                             Text="{Binding Green, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                        <TextBox Grid.Row="2" Grid.Column="1" Style="{StaticResource TextBoxStyle}"
                             Text="{Binding Blue, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                        <TextBox Grid.Row="3" Grid.Column="1" Style="{StaticResource TextBoxStyle}"
                             Text="{Binding Alpha, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=TemplatedParent}}" />

                                        <TextBox Grid.Row="0" Grid.Column="4" Style="{StaticResource TextBoxStyle}"
                             Text="{Binding Hue, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                        <TextBox Grid.Row="1" Grid.Column="4" Style="{StaticResource TextBoxStyle}"
                             Text="{Binding Saturation, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                        <TextBox Grid.Row="2" Grid.Column="4" Style="{StaticResource TextBoxStyle}"
                             Text="{Binding Brightness, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=TemplatedParent}}" />

                                        <!--<Slider Grid.Row="0" Grid.Column="2" Maximum="255" Style="{StaticResource SliderStyle}" Value="{Binding Red, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                            <Slider Grid.Row="1" Grid.Column="2" Maximum="255" Style="{StaticResource SliderStyle}" Value="{Binding Green, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                            <Slider Grid.Row="2" Grid.Column="2" Maximum="255" Style="{StaticResource SliderStyle}" Value="{Binding Blue, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>

                            <Slider Grid.Row="0" Grid.Column="6" Maximum="360" Style="{StaticResource SliderStyle}" Value="{Binding Hue, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                            <Slider Grid.Row="1" Grid.Column="6" Maximum="100" Style="{StaticResource SliderStyle}" Value="{Binding Saturation, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
                            <Slider Grid.Row="2" Grid.Column="6" Maximum="100" Style="{StaticResource SliderStyle}" Value="{Binding Brightness, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>-->


                                        <!--<Slider Grid.Row="3" Grid.Column="2" Maximum="255" Style="{StaticResource SliderStyle}" Value="{Binding Alpha, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>-->

                                        <TextBox Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="4"
                             Style="{StaticResource TextBoxStyle}" TextAlignment="Center"
                             Text="{Binding SelectedColor, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource ColorToHexConverter2}}" />

                                    </Grid>
                                </Border>
                            </StackPanel>
                        </Grid>

                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="SpectrumSliderThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid Background="Transparent" Width="16" Height="9">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="6" />
                            <ColumnDefinition Width="4" />
                            <ColumnDefinition Width="6" />
                        </Grid.ColumnDefinitions>
                        <Polygon Grid.Column="0" Stroke="White" StrokeThickness="1" Fill="Black"
                     Points="-0.5,0  4.5,4.5  -0.5,9" />
                        <Polygon Grid.Column="2" Stroke="White" StrokeThickness="1" Fill="Black"
                     Points="5.5,0  0.5,4.5  5.5,9" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="SunkenFrameStyle" TargetType="{x:Type Label}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <Border Margin="0,1"
                    BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" BorderThickness="1,0,0,0" />
                        <Border Margin="1,0"
                    BorderBrush="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" BorderThickness="0,1,0,0" />
                        <Border Margin="0,1" BorderBrush="#F8F8F8" BorderThickness="0,0,1,0" />
                        <Border Margin="1,0" BorderBrush="#F8F8F8" BorderThickness="0,0,0,1" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ColorPickerRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="IsTabStop" Value="false" />
        <Setter Property="Focusable" Value="false" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border Background="Transparent" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ColorSliderThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid Width="9" Height="12">
                        <Polygon Fill="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"
                     Points="4.5,0 9,5 9,11 0,11 0,5" />
                        <Polygon Fill="Black" Points="4.5,1 8,5 1,5" />
                        <Polygon Stroke="Black" StrokeThickness="1" Points="7.5,5.5 7.5,9.5 1.5,9.5 1.5,5.5" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:ColorSlider}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Maximum" Value="255" />
        <Setter Property="IsTabStop" Value="false" />
        <Setter Property="SmallChange" Value="1" />
        <Setter Property="LargeChange" Value="10" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ColorSlider}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="8*" />
                            <RowDefinition Height="13" />
                            <RowDefinition Height="12*" />
                        </Grid.RowDefinitions>
                        <Border Margin="1" Grid.Row="1" Background="{TemplateBinding Background}" />
                        <Border Margin="1" Grid.Row="1">
                            <Border.Background>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                    <GradientStop
Color="{Binding LeftColor, RelativeSource={RelativeSource TemplatedParent}}" Offset="0" />
                                    <GradientStop
Color="{Binding RightColor,RelativeSource={RelativeSource TemplatedParent}}" Offset="1" />
                                </LinearGradientBrush>
                            </Border.Background>
                        </Border>
                        <Border Margin="1" Grid.Row="1" BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}" />
                        <!--<Label Grid.Row="1" Style="{StaticResource SunkenFrameStyle}"/>-->
                        <Track Grid.Row="1" Margin="-3,0,-2,0" x:Name="PART_Track">
                            <Track.DecreaseRepeatButton>
                                <RepeatButton Style="{StaticResource ColorPickerRepeatButtonStyle}"
                              Command="{x:Static Slider.DecreaseLarge}" />
                            </Track.DecreaseRepeatButton>
                            <Track.IncreaseRepeatButton>
                                <RepeatButton Style="{StaticResource ColorPickerRepeatButtonStyle}"
                              Command="{x:Static Slider.IncreaseLarge}" />
                            </Track.IncreaseRepeatButton>
                            <Track.Thumb>
                                <Thumb x:Name="Thumb" Style="{StaticResource ColorSliderThumbStyle}">
                                    <Thumb.RenderTransform>
                                        <TranslateTransform Y="5" />
                                    </Thumb.RenderTransform>
                                </Thumb>
                            </Track.Thumb>
                        </Track>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:SpectrumSlider}">
        <Setter Property="IsTabStop" Value="false" />
        <Setter Property="Orientation" Value="Vertical" />
        <Setter Property="Maximum" Value="360" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:SpectrumSlider}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="10*" />
                            <ColumnDefinition Width="17" />
                            <ColumnDefinition Width="10*" />
                        </Grid.ColumnDefinitions>
                        <Grid Grid.Column="1">
                            <Border Margin="1" Background="{TemplateBinding Background}" />
                            <Label Style="{StaticResource SunkenFrameStyle}" />
                        </Grid>
                        <Border Grid.Column="1" BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}" />

                        <Track Grid.Column="1" Margin="0,-3" x:Name="PART_Track">
                            <Track.DecreaseRepeatButton>
                                <RepeatButton Style="{StaticResource ColorPickerRepeatButtonStyle}"
                              Command="{x:Static Slider.DecreaseLarge}" />
                            </Track.DecreaseRepeatButton>
                            <Track.IncreaseRepeatButton>
                                <RepeatButton Style="{StaticResource ColorPickerRepeatButtonStyle}"
                              Command="{x:Static Slider.IncreaseLarge}" />
                            </Track.IncreaseRepeatButton>
                            <Track.Thumb>
                                <Thumb x:Name="Thumb" Style="{StaticResource SpectrumSliderThumbStyle}">
                                </Thumb>
                            </Track.Thumb>
                        </Track>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:ColorPicker}">
        <Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
        <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}" />
        <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="Padding" Value="4,3" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ColorPicker}">
                    <Grid Name="MainGrid" SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="8"/>
                        </Grid.ColumnDefinitions>

                        <!-- The Popup color picker panel -->
                        <Popup Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" Placement="Bottom"
                   Margin="1" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
                            <theme:SystemDropShadowChrome Name="Shdw" Color="Transparent" MinWidth="{Binding ActualWidth, ElementName=MainGrid}">
                                <Border x:Name="DropDownBorder" BorderThickness="1"
                        BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
                        Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
                                    <!--<Grid RenderOptions.ClearTypeHint="Enabled">-->
                                    <local:ColorPickerPanel x:Name="PART_ColorPickerPanel"
                                          SelectedColor="{Binding SelectedColor, RelativeSource={RelativeSource Mode=TemplatedParent}}" />

                                </Border>
                            </theme:SystemDropShadowChrome>
                        </Popup>

                        <!-- The Popup dropdown button (arrow) -->
                        <ToggleButton Grid.ColumnSpan="2" Grid.Column="0" Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}" Style="{StaticResource ComboBoxReadonlyToggleButton}"
                          IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" />

                        <!-- The combobox content -->
                        <ContentPresenter Grid.Column="0" IsHitTestVisible="false" Margin="{TemplateBinding Padding}"
                              Content="{Binding SelectedColor, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                              ContentTemplate="{StaticResource ColorPresenterTemplate}" VerticalAlignment="Center"
                              HorizontalAlignment="Stretch"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        </ContentPresenter>

                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger SourceName="PART_Popup" Property="Popup.HasDropShadow" Value="true">
                            <Setter TargetName="Shdw" Property="Margin" Value="0,0,5,5" />
                            <Setter TargetName="Shdw" Property="Color" Value="#71000000" />
                        </Trigger>
                        <!--<Trigger Property="HasItems"
                                 Value="false">
                            <Setter TargetName="DropDownBorder"
                                    Property="Height"
                                    Value="95"/>
                        </Trigger>-->
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground"
                      Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                            <Setter Property="Background" Value="#FFF4F4F4" />
                        </Trigger>
                        <!--<Trigger Property="IsGrouping"
                                 Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll"
                                    Value="false"/>
                        </Trigger>-->
                        <!--<Trigger SourceName="DropDownScrollViewer"
                                 Property="ScrollViewer.CanContentScroll"
                                 Value="false" >
                            <Setter TargetName="OpaqueRect" 
                                    Property="Canvas.Top" 
                                    Value="{Binding ElementName=DropDownScrollViewer, Path=VerticalOffset}" />
                            <Setter TargetName="OpaqueRect" 
                                    Property="Canvas.Left" 
                                    Value="{Binding ElementName=DropDownScrollViewer, Path=HorizontalOffset}" />
                        </Trigger>-->
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <local:HueToColorConverter x:Key="HueToColorConverter" />

    <Style x:Key="HsvControlThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="True" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid Height="12" Width="12">
                        <Ellipse Stroke="White" Margin="0" />
                        <Ellipse Stroke="Black" Margin="1" />
                        <Ellipse Stroke="White" Margin="2" />
                        <Line Stroke="#80000000" X1="0" Y1="6" X2="12" Y2="6" />
                        <Line Stroke="#80000000" X1="6" Y1="0" X2="6" Y2="12" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:HsvControl}">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:HsvControl}">
                    <Grid>
                        <Rectangle>
                            <Rectangle.Fill>
                                <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                    <GradientStop Offset="0" Color="#FFFFFFFF" />
                                    <GradientStop Offset="1"
                                Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Hue, Converter={StaticResource HueToColorConverter}}" />
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Rectangle>
                            <Rectangle.Fill>
                                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                    <GradientStop Offset="0" Color="#00000000" />
                                    <GradientStop Offset="1" Color="#FF000000" />
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}" />
                        <!--<Grid>
                            <Border BorderBrush="#A0808080" BorderThickness="1,1,0,0"/>
                            <Border BorderBrush="#A0F0F0F0" BorderThickness="0,0,1,1"/>
                        </Grid>-->
                        <Canvas ClipToBounds="true">
                            <Thumb Canvas.Left="-5" Canvas.Top="-5" x:Name="PART_Thumb"
                     Style="{StaticResource HsvControlThumbStyle}">
                                <Thumb.RenderTransform>
                                    <TranslateTransform X="0" Y="0" />
                                </Thumb.RenderTransform>
                            </Thumb>
                        </Canvas>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>